import { _decorator, Component, find, Label, Node } from 'cc';
const { ccclass, property } = _decorator;
import goldManager from '../managers/goldManager';
import GlobalEvent from '../Global/GlobalEvent';
import HealthUp from '../managers/healthData/healthUp';
import atkUp from '../managers/atkData/atkUp';
import speedUp from '../managers/speedData/speedUp';

@ccclass('buySpeedBtn')
export class buySpeedBtn extends Component {
    @property(Node)
    private speedBtn: Node = null;
    @property(Node)
    private speedLv: Node = null;
    @property(Node)
    private LvScore: Node = null;
    @property(Node)
    private goldView: Node = null;
    @property(Node)
    @property(Node)
    private btn_Add_speed: Node = null;
    @property(Node)
    private btn_Add_speed2: Node = null;


    private bool = false;
    private bgMoveLeft;

    private getSpeed;
    private getGoldBtn;
    private goldSpeed;
    private goldGetLv;

    start() {
        GlobalEvent.on('getSpeedBoolean', (e) => {
            this.speedBtn.active = e;
        })
        
        const speedup = speedUp.getInstance();
        const goldmanager = goldManager.getInstance();
        this.getGoldBtn = speedup.addSpeedFun();
        this.getSpeed = goldmanager.getGold();

        if (this.goldView) {
            const label = this.goldView.getComponent(Label);
            label.string = `金币:${this.getSpeed}`;
        }

    }



    //购买攻击速度按钮
    speedBtnFun() {
        const goldmanager = goldManager.getInstance();
        const speedup = speedUp.getInstance();
        //点击购买 增加lv
        speedup.upLv();
        const healthup = HealthUp.getInstance();
        const atkup = atkUp.getInstance();
        //获取购买的等级
        const goldGetLv = speedup.getlv();
        //获取购买的攻速
        const goldSpeed = speedup.addSpeedFun();
        
        this.getGoldBtn = speedup.addgold();
        goldmanager.btnMinuGold(this.getGoldBtn);
        speedup.getSpeedBool();
        healthup.getHealthbool();
        atkup.getAtkbool();


        //获取购买攻击速度的金币
        this.goldSpeed = goldSpeed;
        this.goldGetLv = goldGetLv;

        this.renderGold();

    }


    

    //渲染攻击速度
    renderGold() {
        const goldmanager = goldManager.getInstance();
        let speedup = speedUp.getInstance();
        const goldGetLv = speedup.getlv();
        const goldSpeed = speedup.addSpeedFun();
        
        this.getSpeed = goldmanager.getGold();
        this.getGoldBtn = speedup.addgold();


        //获取购买攻击速度的金币
        this.goldGetLv = goldGetLv;
        this.goldSpeed = goldSpeed;

        const goldview = this.goldView.getComponent(Label);
        goldview.string = `金币:${this.getSpeed}`;

        const speedLv = this.speedLv.getComponent(Label);
        speedLv.string = `Lv.${this.goldGetLv}`;

        const LvScore = this.LvScore.getComponent(Label);
        LvScore.string = `+${this.goldSpeed}`;

        const btn_Add_speed = this.btn_Add_speed.getComponent(Label);
        btn_Add_speed.string = `${this.getGoldBtn}`;

        const btn_Add_speed2 = this.btn_Add_speed2.getComponent(Label);
        btn_Add_speed2.string = `${this.getGoldBtn}`;


    }
}

